function UserUATMzpdHz() {
    this.form = this.InitForm();
    this.tab = this.InitEleUI();
    this.table = this.InitTable();

    $("#year").val($("#hidyear").val());
    this.form.render('select');

    this.currenttabindex = 0;
    this.InitGrid();
}

UserUATMzpdHz.prototype.InitGrid = function () {
    var year = $("#year").val();
    var quarter = $('input[name="quarter"]:checked ').val();

    var _this = this;
    window.liger.remove("listorg");
    if (_this.grid == null) {
        _this.grid = $("#listorg").ligerGrid({
            columns: [
                //{ display: '序号', width: 80, name: 'rowNum' },
                {display: '机构名称', width: 250, align: 'left', name: 'orgname', id: "orgname"},
                {display: '年份', width: 100, name: 'year'},
                {display: '季度', width: 100, name: 'quarter'},
                {display: '参加考核人数', width: 100, name: 'usercount',
                    render:function(rowData){
                        if(rowData.realcount ==undefined ||rowData.realcount ==null||rowData.realcount ==''){
                            console.log("1:"+rowData.usercount);
                            return rowData.usercount;
                        }else{
                            console.log("2:"+rowData.realcount);
                            return rowData.realcount;
                        }
                    }
                },
                {
                    display: '状态', width: 100, name: 'status', render: function (rowdata, rowindex, value) {
                        if (rowdata.status == 1) {
                            return "提交";
                        }
                        else if (rowdata.status == 2) {
                            return "归档";
                        }
                        else if (rowdata.status == 3) {
                            return "驳回";
                        }
                    }
                },
                {display: '说明', width: 120, name: 'remark'},
                {
                    display: '自评', columns:
                        [
                            {display: '总计', name: 'zpcount', align: 'center', width: 60},
                            {display: '填写', name: 'zptxcount', width: 60, align: 'center'},
                            {display: '提交', name: 'zptjcount', width: 60, align: 'center'},
//                          { display: '审核', name: 'zpshcount', width: 60, align: 'center' },
//                          { display: '归档', name: 'zpgdcount', width: 60, align: 'center' },
//                          { display: '驳回', name: 'zpbhcount', width: 60, align: 'center' }
                    ]
                },
                {
                    display: '互评', columns:
                        [
                            {display: '总计', name: 'hpcount', align: 'center', width: 60},
                            {display: '填写', name: 'hptxcount', width: 60, align: 'center'},
                            {display: '提交', name: 'hptjcount', width: 60, align: 'center'},
//                           { display: '审核', name: 'hpshcount', width: 60, align: 'center' },
//                           { display: '归档', name: 'hpgdcount', width: 60, align: 'center' },
//                           { display: '驳回', name: 'hpbhcount', width: 60, align: 'center' }
                    ]
                },
                {
                    display: '领导评价', columns:
                        [
                            {display: '总计', name: 'ldcount', align: 'center', width: 60},
                            {display: '填写', name: 'ldtxcount', width: 60, align: 'center'},
                            {display: '提交', name: 'ldtjcount', width: 60, align: 'center'},
//                            { display: '审核', name: 'ldshcount', width: 60, align: 'center' },
//                            { display: '归档', name: 'ldgdcount', width: 60, align: 'center' },
//                            { display: '驳回', name: 'ldbhcount', width: 60, align: 'center' }
                    ]
                },
                {
                    display: '民主评定', columns:
                        [
                            {display: '总计', name: 'mzpdcount', align: 'center', width: 60},
                            {display: '填写', name: 'mzpdtxcount', width: 60, align: 'center'},
                            {display: '提交', name: 'mzpdtjcount', width: 60, align: 'center'},
//                             { display: '审核', name: 'mzpdshcount', width: 60, align: 'center' },
//                             { display: '归档', name: 'mzpdgdcount', width: 60, align: 'center' },
//                             { display: '驳回', name: 'mzpdbhcount', width: 60, align: 'center' }
                    ]
                },
                {
                    display: '操作', width: 100, name: 'userid', render: function (rowdata, rowindex, value) {
                        var html = '';
                        if (rowdata.usercount > 0) {
                        	 	if (rowdata.mzpdtjcount==0) {
                                html += ' <img class="btn-img" src="' + ctxStatic + '/images/button/tijiao.png" onclick="vUserUATMzpdHz.BmTiJiao(' + rowdata.orgid + ',' + rowdata.year + ',' + rowdata.quarter + ',1,' + rowdata.orgstatustjid + ')"  alt="提交" title="提交">';
                        	 }
                             console.log(rowdata.orgname+':'+rowdata.usercount+' '+rowdata.mzpdtxcoun+' '+rowdata.realcount );
                            console.log("first:"+rowdata.status);
                            html += ' <img class="btn-img" src="' + ctxStatic + '/images/button/detail.png" onclick="vUserUATMzpdHz.ChangeTab(1,' + rowdata.orgid + ',' + rowdata.status + ')"  alt="详情" title="详情"> ';
                        }
                        return html;
                    }
                }
            ],
            pageSize: 30,
            url: "get_list_org" + '?time=' + new Date().getTime(),
            delayLoad: false,            //初始化时是否加载,为true时,不加载,为false时,则加载
            sortName: null,
            dataAction: 'server',
            parms: {
                Method: "",
                year: year, quarter: quarter
            },
            sortOrder: null,
            sourceObj: _this.grid,
            root: 'items',                       //数据源字段名
            record: 'countRecord',                    //数据源记录数字段名
            pageParmName: 'CurrentPage',               //页索引参数名，(提交给服务器)
            pagesizeParmName: 'PageSize',        //页记录数参数名，(提交给服务器)
            data: {},
            width: "100%",
            height: '100%',
            heightDiff: 0,
            rowHeight: 28,
            onSuccess: function (rowdata, rowindex) {
                if (rowdata.status > 0) {
                    alert(rowdata.msg)
                }
            },
            alternatingRow: true,
            border: 0,
            usePager: false,
            tree: {
                columnId: "orgname",
                idField: "orgid",
                parentIDField: "orgparentid"

            }
        })
    }
}

UserUATMzpdHz.prototype.InitForm = function () {
    var form;
    layui.use('form', function () {
        form = layui.form; //只有执行了这一步，部分表单元素才会自动修饰成功
        form.on('select(year)', function (data) {
            vUserUATMzpdHz.InitPage();
        });
        form.on('radio(quarter)', function (data) {
            vUserUATMzpdHz.InitPage();
        })
        form.render();
    });
    return form;
}


UserUATMzpdHz.prototype.InitEleUI = function () {
    var element;
    var _this = this;
    layui.use('element', function () {
        element = layui.element;

        element.on('tab(tabcontent)', function (data) {
            vUserUATMzpdHz.currenttabindex = data.index;
            if (data.index == 1) {
                _this.searchtable();
            }
            if (data.index == 0) {
                $("#hidorgid").val("");
                $("#hidstatus").val("");
            }
        });
    })
    return element;
}

UserUATMzpdHz.prototype.InitTable = function () {
    var table;
    var _this = this;
    layui.use('table', function () {
        table = layui.table;
        table.render({
            elem: '#list'
            , height: $(window).height() - 150
            , url: 'get_list' // 数据接口
            , page: true // 开启分页
            , limit: 40
            , id: 'useruatmapdlist'
            , limits: [20, 40, 80, 100]
            , method: "post"
            , cols: [[ // 表头
                //{type:'numbers'}
                //,{field : 'rowNum',title : '序号',width : 80,align : 'center'}
                {field: 'realname', title: '姓名', width: "7%", align: 'center', fixed: 'left', templet: '#realnameTpl'}
                , {field: 'cardno', title: '身份证号', width: "15%", align: 'center'}
                , {field: 'realorgname', title: '实际工作单位', width: "15%", align: 'center'}
                , {field: 'year', title: '年份', width: "5%", align: 'center'}
                , {field: 'quarter', title: '季度', width: "7%", align: 'center'}
                , {field: 'status', title: '状态', width: "6%", align: 'center'}

                , {title: '进度', width: "21%", align: 'center', toolbar: '#process'}
                //, {field : 'khzq',title : '考核周期',width : 250,align : 'center'}
                , {field: 'pskhzhdf', title: '综合得分', width: "7%", align: 'center'}
                , {title: '特殊事项说明', width: "6%", align: 'center', toolbar: '#operate1'}
                // , {field : 'createtime',title : '填写时间',width : 170,align : 'center'}
                , {title: '操作', width: "10%", align: 'center', toolbar: '#operate'}
            ]]
            , request: {
                type: 'post'
            }
            , where: {
                year: $("#year").val(),
                quarter: $("#quarter").val(),
                realname: $("#realname").val(),
                orgid: $("#hidorgid").val(),
                status:$("#hidstatus").val()
            }
            , done: function (res, page, count) {
                $("[data-field='quarter']").children().each(function (index) {
                    var text = $(this).text();
                    switch (text) {
                        case "1":
                            $(this).text('第一季度');
                            break;
                        case "2":
                            $(this).text('第二季度');
                            break;
                        case "3":
                            $(this).text('第三季度');
                            break;
                        case "4":
                            $(this).text('第四季度');
                            break;
                    }
                })
                $("[data-field='status']").children().each(function (index) {
                    var text = $(this).text();

                    switch (text) {
                        case "-1":
                            $(this).text('未填写');
                            break;
                        case "0":
                            $(this).text('已填写');
                            break;
                        case "1":
                            $(this).text('提交');
                            break;
                        case "2":
                            $(this).text('审核');
                            break;
                        case "3":
                            $(this).text('归档');
                            break;
                        case "4":
                            $(this).text('驳回');
                            break;
                    }
                })
                // $("[data-field='realorgname']").children().each(function(index){
                //     if (index > 0) {
                //         var thisdata = dataarr[index - 1];
                //         var text = $(this).text();
                //         if (text == null || text == ''){
                //             var orgname = thisdata.orgname;
                //             console.log(1);
                //             $(this).text(orgname);
                //         }
                //     }
                // })
            }

        });


        //监听工具条
        table.on('tool(list)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                vUserUATMzpdHz.ChangeTab(2, data.mzpdid,data.status);
            } else if (obj.event === 'del') {
                top.mylayui.confirm('确定要删除吗？', {icon: 0}, function (index, dd) {
                    top.mylayui.close(index);
                    vUserUATMzpdHz.deleteentity(data.mzpdid);
                });
            } else if (obj.event === 'edit') {
                vUserUATMzpdHz.openadd(data.mzpdid, data.userid, data.year, data.quarter);
            }
            else if (obj.event === 'add') {
                vUserUATMzpdHz.openadd(0, data.userid, data.year, data.quarter);
            }
            else if (obj.event === 'tijiao') {
                top.mylayui.confirm('提交后不允许修改，确定要提交吗？', {icon: 0}, function (index) {
                    top.mylayui.close(index);
                    vUserUATMzpdHz.updatestatus(data.mzpdid, 1, data.year, data.quarter, data.userid);
                });
            }
            else if (obj.event === 'wjsm') {
                vUserUATMzpdHz.openwjsm(obj.data.userid, data.year, data.quarter);
            }
        });


    });

    return table;
}

UserUATMzpdHz.prototype.openadd = function (mzpdid, userid, year, quarter) {
//	top.mylayui.open({
//        type: 2,
//        title: '填写评价',
//        shadeClose: true,
//        shade: 0.5,
//        area: ['900px', '600px'],
//        content: 'useruatmzpd/user_usasstemp_mzpd_edit'
//      }); 
//	if(mzpdid>0){
//		top.mylayui.open({
//	        type: 2,
//	        title: '填写评价',
//	        shadeClose: true,
//	        shade: 0.5,
//	        area: ['900px', '600px'],
//	        content: 'useruatmzpd/user_usasstemp_mzpd_edit_new?mzpdid='+mzpdid+"&userid="+userid+"&year="+year+"&quarter="+quarter
//	      });
//	}
//	else{
//		top.mylayui.open({
//	        type: 2,
//	        title: '填写评价',
//	        shadeClose: true,
//	        shade: 0.5,
//	        area: ['900px', '600px'],
//	        content: 'useruatmzpd/user_usasstemp_mzpd_data_checked?mzpdid='+mzpdid+"&userid="+userid+"&year="+year+"&quarter="+quarter
//	      });
//	}

    top.mylayui.open({
        type: 2,
        title: '填写评价',
        shadeClose: true,
        shade: 0.5,
        area: ['900px', '600px'],
        content: 'useruatmzpd/user_usasstemp_mzpd_edit_new?mzpdid=' + mzpdid + "&userid=" + userid + "&year=" + year + "&quarter=" + quarter
    });

}

UserUATMzpdHz.prototype.addresult = function (result, msg) {
    if (result > 0) {
        top.mylayui.msg('操作成功', {icon: 1});
        top.mylayui.closeAll('iframe');
        //vUser.searchtable();
        vUserUATMzpdHz.searchtable();
    }
    else {
        if (msg) {
            top.mylayui.msg(msg, {icon: 0});
        } else {
            top.mylayui.msg('操作失败', {icon: 0});
        }
    }
}

UserUATMzpdHz.prototype.searchtable = function () {
    //vUserUATMzpd.ChangeTab(1);
    var year = $("#year").val();
    var quarter = $('input[name="quarter"]:checked ').val();
    this.table.reload('useruatmapdlist', {
        page: {
            curr: 1 //重新从第 1 页开始
        }
        , where: {
            year: year,
            quarter: quarter,
            realname: $("#realname").val(),
            orgid: $("#hidorgid").val(),
            status:$("#hidstatus").val()
        }
    });
}


UserUATMzpdHz.prototype.deleteentity = function (mzpdid) {
    $.ajax({
        type: "POST",
        url: "delete_mzpd",
        data: {mzpdid: mzpdid},
        beforeSend: function (XHR) {

        },
        success: function (data) {
            data = eval('(' + data + ')');
            if (data.result > 0) {
                top.mylayui.msg(data.msg, {icon: 1});
                document.location.reload();
            }
            else {
                top.mylayui.msg(data.msg, {icon: 0});
            }
        },
        complete: function (XHR) {

        },
        error: function () {

        }
    });
}

UserUATMzpdHz.prototype._exportentity=function(mzpdid){

    vUserUATMzpdHz.exportentity(mzpdid);
}
UserUATMzpdHz.prototype.exportentity = function (mzpdid) {
    top.ShowZheZhao();
    $.ajax({
        type: "POST",
        url: "export_mzpd",
        data: {mzpdid: mzpdid},
        beforeSend: function (XHR) {

        },
        success: function (data) {
            data = eval('(' + data + ')');
            if (data.result > 0) {
                //top.mylayui.msg('导出成功', {icon: 1});
                //document.location.reload();
                window.open(data.msg, '_self');

            }
            else {
                top.mylayui.msg(data.msg, {icon: 0});
            }
            top.ShowZheZhao();
        },
        complete: function (XHR) {
            top.mylayui.closeAll('loading');
        },
        error: function () {

        }
    });
}

UserUATMzpdHz.prototype._changeTab=function(){
     UserUATMzpdHz.ChangeTab(1)
}
UserUATMzpdHz.prototype.ChangeTab = function (index, mzpdid,status) {
    this.tab.tabChange('tabcontent', index);
    console.log("two:"+status);
    if (mzpdid) {
        if (index == 1) {
            $("#hidorgid").val(mzpdid);
            $("#hidstatus").val(status);
            vUserUATMzpdHz.searchtable();
        }
        else {
            vUserUATMzpdHz.InitIfream(mzpdid);
        }

    }

}
UserUATMzpdHz.prototype.InitIfream = function (mzpdid) {

    $("#getdata").attr("src", "user_usasstemp_mzpd_detail?mzpdid=" + mzpdid);
}


UserUATMzpdHz.prototype.searchlist = function () {
    var year = $("#year").val();
    var quarter = $('input[name="quarter"]:checked ').val();
    this.grid.setOptions({
        newPage: 1, parms: {
            Method: "",
            year: year, quarter: quarter
        }
    });
    this.grid.loadData();
}

UserUATMzpdHz.prototype.InitPage = function () {
    if (vUserUATMzpdHz.currenttabindex == 0) {
        vUserUATMzpdHz.searchlist();
    }
    else if (vUserUATMzpdHz.currenttabindex == 1) {
        vUserUATMzpdHz.searchtable();
    } else {
        //vUserUsAssTempLd.InitIfream();
    }
}

UserUATMzpdHz.prototype.BmTiJiao = function (orgid, year, quarter, status, orgstatustjid) {
    top.mylayui.confirm('提交后不允许修改，确定要提交吗？', {icon: 0}, function (index) {
        top.mylayui.close(index);
        $.ajax({
            type: "POST",
            url: "update_mzpd_status_bm",
            data: {orgid: orgid, year: year, quarter: quarter, status: status, orgstatustjid: orgstatustjid},
            beforeSend: function (XHR) {

            },
            success: function (data) {
                data = eval('(' + data + ')');
                if (data.result > 0) {
                    top.mylayui.msg(data.msg, {icon: 1});
                    //vOrg.searchtable();
                    vUserUATMzpdHz.InitPage();
                }
                else {
                    top.mylayui.msg(data.msg, {icon: 0});
                }
            },
            complete: function (XHR) {

            },
            error: function () {

            }
        });

    })

}

UserUATMzpdHz.prototype.updatestatus = function (mzpdid, status, year, quarter, userid) {
    $.ajax({
        type: "POST",
        url: "update_mzpd_status",
        data: {mzpdid: mzpdid, status: status, year: year, quarter: quarter, userid: userid},
        beforeSend: function (XHR) {

        },
        success: function (data) {
            data = eval('(' + data + ')');
            if (data.result > 0) {
                top.mylayui.msg(data.msg, {icon: 1});
                //vOrg.searchtable();
                vUserUATMzpdHz.searchtable();
            }
            else {
                top.mylayui.msg(data.msg, {icon: 0});
            }
        },
        complete: function (XHR) {

        },
        error: function () {

        }
    });
}

UserUATMzpdHz.prototype.openwjsm = function (userid, year, quarter) {

    top.mylayui.open({
        type: 2,
        title: false,
        shadeClose: true,
        shade: 0.5,
        area: ['700px', '250px'],
        content: 'common/user_vtdp?userid=' + userid + "&year=" + year + "&quarter=" + quarter
    });

}

var vUserUATMzpdHz = null;
$(function () {
    vUserUATMzpdHz = new UserUATMzpdHz();
})